package com.krtech.wecard.module.sys.controller;

import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import com.krtech.wecard.framework.aop.Metrics;
import com.krtech.wecard.framework.model.CommRes;
import com.krtech.wecard.framework.security.Inner;
import com.krtech.wecard.module.sys.pojo.PublicSignitureVo;
import com.krtech.wecard.module.sys.pojo.WxAuth;
import com.krtech.wecard.module.sys.service.LoginService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

@Api(tags = "微信认证授权")
@Controller
@Slf4j
@Metrics
public class WxLoginController {

    @Autowired
    private LoginService loginService;

    /**
     * 微信 普通用户登陆
     *
     * @param code
     * @param phone
     * @return
     */
    @PostMapping("/api/v1/wxLogin")
    @ApiOperation(value = "微信登陆")
//    @Inner(value = false)
    @ResponseBody
    public CommRes wxLogin(@RequestBody WxAuth wxAuth) {
        return loginService.wxLogin(wxAuth);
    }

    /**
     * 微信 管理用户登陆 （开放平台管理员登陆）
     *
     * @param code
     * @param phone
     * @return
     */
    @GetMapping("/api/v1/wxAdminLogin")
    @ApiOperation(value = "微信超级管理员登陆")
//    @Inner(value = false)
    public String wxAdminLogin(String code, String state) {
        return loginService.wxAdminLogin(code,state);
    }

    /**
     * 微信 公众号授权
     *
     * @param code
     * @param phone
     * @return
     */
    @GetMapping("/api/v1/wxPublicLogin")
    @ApiOperation(value = "公众号授权")
    public String wxPublicLogin(String code, String state) {
        return loginService.wxPublicLogin(code,state);
    }

    /**
     * 微信 公众号消息授权
     *
     * @param code
     * @param phone
     * @return
     */
    @GetMapping("/api/v1/wxPublicMessageLogin")
    @ApiOperation(value = "公众号消息授权")
    public String wxPublicMessageLogin(String code, String state) {
        return loginService.wxPublicMessageLogin(code,state);
    }


    /**
     * 微信 公众号授权
     *
     * @param code
     * @param phone
     * @return
     */
    @GetMapping("/api/v1/wxPublicJudgeFocus")
    @ApiOperation(value = "公众号判断是否关注公众号")
    public String wxPublicJudgeFocus(String code, String state) {
        return loginService.wxPublicJudgeFocus(code,state);
    }

    /**
     * 微信 公众号授权，获得token
     *
     * @param code
     * @param phone
     * @return
     */
    @GetMapping("/api/v1/wxPublicGetWecard")
    @ApiOperation(value = "公众号授权，获得token")
    public String wxPublicGetWecard(String code, String state) {
        return loginService.wxPublicGetWecard(code,state);
    }



    /**
     * 微信 获得公众号签名
     *
     * @param code
     * @param phone
     * @return
     */
    @GetMapping("/api/v1/getPubliSigniture")
    @ApiOperation(value = "获得公众号签名")
    @ResponseBody
    public PublicSignitureVo getPubliSigniture() {
        return loginService.getPubliSigniture();
    }

}
